#include "mat.h"
#include "allocator.h"
#include <iostream>
#include <stdlib.h>

/**
 * @descriptor:单单只是为了演示抽象类
 * @note:
 * @author: modmvp
 * @date: 2021-01-19
 * @version: 10.0.2
*/

class myAllocator:public ncnn::Allocator
{
public:
    void *fastMalloc(size_t size){
        char *ptr = (char*)malloc(size);
        return (void*)ptr;
    }

    void fastFree(void *ptr){
        free(ptr);
    }
};

int main(void)
{
    ncnn::Allocator *ptr = new myAllocator();
    // 证明Mat的拷贝构造函数是浅拷贝
    ncnn::Mat cons1(10, (size_t)4, (ncnn::Allocator*)ptr);
    std::cout << cons1.w << std::endl;
    std::cout << "cons1 address: " << cons1.data << std::endl;
    ncnn::Mat cons12(cons1);
    std::cout << "cons12 address: " << cons12.data << std::endl;
    ncnn::Mat cons13(cons1);
    std::cout << "cons13 address: " << cons13.data << std::endl;
    // 数据引用计数
    std::cout << "cons1 ref count: " << *cons1.refcount << std::endl;
    // Mat 的数据区域为data + ref count组成
    std::cout << cons1.w << " "<< cons1.cstep << " " << cons1.total() << std::endl;
    return 0;
}
